#include "RigidBody2.h"

RigidBody2::RigidBody2()
{
	m_mass = 1.0f;
	m_position = D3DXVECTOR3(0.0f, 0.0f, 0.0f); // centre of mass
	m_oldPosition = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	m_acceleration = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	m_velocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	m_force = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

	m_rotVelocity = 0.0f;
	m_rotAcceleration = 0.0f;
	m_torque = 0.0f;
	m_moment = 0.0f; //of intertia

	m_posCalc = EULER;
	m_rbType = CUBE;

}

void RigidBody2::operator=(const RigidBody2& rh)
{	
	m_mass = rh.m_mass;
	m_position = rh.m_position;
	m_oldPosition = rh.m_oldPosition;
	m_acceleration = rh.m_acceleration;
	m_velocity = rh.m_velocity;
	m_force = rh.m_force;

	m_rotVelocity = rh.m_rotVelocity;
	m_rotAcceleration = rh.m_rotAcceleration;
	m_torque = rh.m_torque;
	m_moment = rh.m_moment;

	m_posCalc = rh.m_posCalc;
}

const RBTYPE RigidBody2::GetType() const
{
	return m_rbType;
}

const float RigidBody2::GetMass() const
{
	return m_mass;
}

void RigidBody2::SetMass(float mass)
{
	m_mass = mass;
	if (m_mass == 0.0f)
	{
		m_inverseMass = 0.0f;
	}
	else
	{
		m_inverseMass = 1.0f / m_mass;
	}
}

const D3DXVECTOR3& RigidBody2::GetPosition() const
{
	return m_position;
}

void RigidBody2::SetPosition(const D3DXVECTOR3& position)
{
	m_position = position;
}

const D3DXVECTOR3& RigidBody2::GetAccleration() const
{
	return m_acceleration;
}

void RigidBody2::SetAcceleration(const D3DXVECTOR3& acceleration)
{
	m_acceleration = acceleration;
}

const D3DXVECTOR3& RigidBody2::GetVelocity() const
{
	return m_velocity;
}

void RigidBody2::SetVelocity(const D3DXVECTOR3& velocity)
{
	m_velocity = velocity;
}
const D3DXVECTOR3& RigidBody2::GetOldVelocity() const
{
	return m_oldVelocity;
}

void RigidBody2::SetOldVelocity(const D3DXVECTOR3& oldVelocity)
{
	m_oldVelocity = oldVelocity;
}

const D3DXVECTOR3& RigidBody2::GetForce() const
{
	return m_acceleration * m_mass;
}

void RigidBody2::SetForce(const D3DXVECTOR3& force)
{
	m_force = force;
}

void RigidBody2::AddForce(const D3DXVECTOR3& force)
{
	m_force += force;
}

const float RigidBody2::GetRotation() const
{
	return m_rotation;
}

void RigidBody2::SetRotation(float rotation)
{
	m_rotation = rotation;
}

const float RigidBody2::GetRotationalVelocity() const
{
	return m_rotVelocity;
}

void RigidBody2::SetRotationalVelocity(float velocity)
{
	m_rotVelocity = velocity;
}

const float RigidBody2::GetRotationalAcceleration() const
{
	return m_rotAcceleration;
}

void RigidBody2::SetRotationalAccleration(float acceleration)
{
	m_rotAcceleration = acceleration;
}

const float RigidBody2::GetTorque() const
{
	return m_torque;
}

void RigidBody2::SetTorque(float torque)
{
	m_torque = torque;
}

const float RigidBody2::GetMoment() const
{
	return m_moment;
}

void RigidBody2::SetMoment(float moment)
{
	m_moment = moment;
}